package com.tiancheng.trade.order.controller.app;

import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.order.util.SecurityUtils;
import com.tiancheng.trade.order.service.InvoiceOrderService;
import com.tiancheng.trade.order.vo.app.InvoiceMakeVO;
import com.tiancheng.trade.order.vo.app.InvoiceOrderQueryVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * 发票移动端接口
 *
 * @author kellen
 * @date 2024/6/27
 */
@RestController
@RequestMapping("/app/invoice")
public class InvoiceAppController {

    @Resource
    private InvoiceOrderService invoiceOrderService;

    /**
     * 开具发票
     * @param makeVO
     * @return
     */
    @PostMapping(value = "/make", consumes = MediaType.APPLICATION_JSON_VALUE)
    public Result make(@RequestBody @Valid InvoiceMakeVO makeVO) {
        String uid = SecurityUtils.getLoginUserId();
        return Result.success(invoiceOrderService.make(uid, makeVO));
    }

    /**
     * 查询旅行商品未开票订单
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/orders")
    public Result orders(@RequestParam("page") int page, @RequestParam("size") int size) {
        String uid = SecurityUtils.getLoginUserId();

        InvoiceOrderQueryVO queryVO = new InvoiceOrderQueryVO();
        queryVO.setPage(page);
        queryVO.setSize(size);

        return Result.success(invoiceOrderService.query(uid, queryVO));
    }

    /**
     * 查询诚选未开票订单
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/shoppingOrders")
    public Result shoppingOrders(@RequestParam("page") int page, @RequestParam("size") int size) {
        String uid = SecurityUtils.getLoginUserId();

        InvoiceOrderQueryVO queryVO = new InvoiceOrderQueryVO();
        queryVO.setPage(page);
        queryVO.setSize(size);
        queryVO.setOrderSource("89");

        return Result.success(invoiceOrderService.query(uid, queryVO));
    }

    /**
     * 查看可开票的订单详细
     * @param orderId
     * @return
     */
    @GetMapping("/orderDetail")
    public Result orderDetail(@RequestParam("order_id") String orderId) {
        String uid = SecurityUtils.getLoginUserId();
        return Result.success(invoiceOrderService.detail(uid, orderId));
    }

    /**
     * 重新开票
     * @param makeVO
     * @return
     */
    @PostMapping(value = "/reset", consumes = MediaType.APPLICATION_JSON_VALUE)
    public Result reset(@RequestBody @Valid InvoiceMakeVO makeVO) {
        String uid = SecurityUtils.getLoginUserId();
        invoiceOrderService.reset(uid, makeVO);
        return Result.success();
    }
}
